package com.hspedu.newData.dmsxl.栈;

import org.junit.Test;

import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Stack;

/**
 * @Author: yh
 * @description:
 * @CreateTime: 2025-04-28
 * @Version: 1.0
 */

public class LC232用栈实现队列 {

    class MyQueue {
        Stack<Integer> stack1;
        Stack<Integer> stack2;

        public MyQueue() {
            stack1 = new Stack<>();
            stack2 = new Stack<>();
        }

        public void push(int x) {
            stack1.push(x);
        }

        public int pop() {
            if (stack2.empty()){
                in2out();
            }
            return stack2.pop();
        }

        public int peek() {
            if (stack2.empty()){
                in2out();
            }
            return stack2.peek();
        }

        public boolean empty() {
            return stack1.empty() && stack2.empty();
        }

        private void in2out(){
            while(!stack1.isEmpty()){
                stack2.push(stack1.pop());
            }
        }

    }

    @Test
    public void test() {
        MyQueue obj = new MyQueue();
        obj.push(1);
        obj.push(2);
        int param_2 = obj.pop();
        boolean param_4 = obj.empty();
        System.out.println("-=");
    }


}
